// 页面路径：store/index.js 
import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex); //vue的插件机制

//Vuex.Store 构造器选项
const store = new Vuex.Store({
	state: {
		currentLanguage: uni.getStorageSync('language') || ''
	},
	mutations: {
		changeLanguage(state) {
			uni.showActionSheet({
				itemList: [
					// this.$t('public.en'),
					// this.$t('public.zh-Hans'),
					// this.$t('public.es'),
					'English',
					'中文简体',
					// '中文繁体'
				],
				success: (res) => {
					//#ifdef  H5
					window.location.reload()
					//#endif
					//#ifdef  APP-PLUS

					//#endif

					const language = [{
							text: '英文',
							code: 'en'
						},
						{
							text: '中文简体',
							code: 'zh-Hant'
						}
						// {text:'中文繁体',code:'zh-Hant'},
					]
					uni.setStorageSync('language', language[res.tapIndex].code)

					this.$i18n.locale = language[res.tapIndex].code
					uni.setLocale(language[res.tapIndex]
						.code) //切换语言环境必须在this.$i18n.locale之后，否则app端会有意想不到的bug
				},
				fail: function(res) {}
			});
		},
	},
	actions: {

	},
	getters: {

	}
})
export default store